package main

import (
	"context"
	"fmt"
	"google.golang.org/grpc"
	"sale_system/userop_srv/proto"
)

var clientMessage proto.MessageClient
var clientAddress proto.AddressClient
var clientUserFav proto.UserFavClient

var conn *grpc.ClientConn

func Init() {
	var err error

	conn, err = grpc.Dial("192.168.56.103:8899", grpc.WithInsecure())
	if err != nil {
		panic("failed to connect, " + err.Error())
	}

	clientMessage = proto.NewMessageClient(conn)
	clientAddress = proto.NewAddressClient(conn)
	clientUserFav = proto.NewUserFavClient(conn)
}

func TestCreateAddress(userId int) {

	request := proto.AddressRequest{
		UserId:       int32(userId),
		Province:     "广东省",
		City:         "珠海市",
		District:     "香洲区",
		SignerName:   "陈志鸿",
		SignerMobile: "13147065653",
	}

	rsp, err := clientAddress.CreateAddress(context.Background(), &request)
	if err != nil {
		panic(err)
	}
	fmt.Println(rsp)
}
func TestUpdateAddress() {
	request := proto.AddressRequest{
		Id:           6,
		UserId:       17,
		Province:     "广东",
		City:         "珠海市",
		District:     "香洲区",
		SignerName:   "陈志鸿",
		SignerMobile: "13147065653",
	}

	_, err := clientAddress.UpdateAddress(context.Background(), &request)
	if err != nil {
		panic(err)
	}
}
func TestDeleteAddress() {
	request := proto.AddressRequest{
		Id:     8,
		UserId: 18,
	}

	_, err := clientAddress.DeleteAddress(context.Background(), &request)
	if err != nil {
		panic(err)
	}
}
func TestGetAddressList() {
	request := proto.AddressRequest{
		UserId: 18,
	}
	clientMessage, err := clientAddress.GetAddressList(context.Background(), &request)
	if err != nil {
		panic(err)
	}
	fmt.Println(clientMessage)
}

func main() {

	Init()
	defer conn.Close()
}
